package com.tulele.vtool.handler;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.tulele.vtool.model.SysDict;
import com.tulele.vtool.model.respEntity.RespData;
import com.tulele.vtool.model.respEntity.ReturnCode;
import com.tulele.vtool.service.IUserBrandInfoService;
import com.tulele.vtool.service.IUserInfoService;
import com.tulele.vtool.service.SysDictService;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据字典表(SysDict)表控制层
 *
 * @author makejava
 * @since 2020-07-19 19:07:18
 */
@Slf4j
@RestController
public class SysDictHandler {
    @Autowired
    private IUserBrandInfoService userBrandInfoService;

    @Autowired
    private IUserInfoService userInfoService;
    /**
     * 服务对象
     */
    @Autowired
    private SysDictService sysDictService;

    /**
     * 通过SysDict查询数据
     *
     * @param sysDict
     * @return List<SysDictRespEntity>
     */
    @PostMapping(value = "/selectSysDict", produces = "application/json;charset=UTF-8")
    public RespData selectSysDict(@RequestHeader("userId") String userId, @RequestBody SysDict sysDict) {
        RespData respData = new RespData();
        if (null == sysDict || StringUtils.isBlank(userId)) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        List<SysDict> SysDictService = this.sysDictService.selectSysDict(sysDict);
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        resultMap.put("SysDictService", SysDictService);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    /**
     * 通过SysDict查询数据
     *
     * @param sysDict
     * @return List<SysDictRespEntity>
     */
    @PostMapping(value = "/selectIdByName", produces = "application/json;charset=UTF-8")
    public RespData selectIdByName(@RequestHeader("userId") String userId, @RequestParam("sysDict") String sysDict) {
        RespData respData = new RespData();
        if (null == sysDict || StringUtils.isBlank(userId)) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        Integer SysDictIdService = this.sysDictService.selectIdByName(sysDict);
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);

        resultMap.put("SysDictIdService", SysDictIdService);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

}
